package com.swt.gap.controller;

import com.swt.gap.common.constant.CommonConstant;
import com.swt.gap.model.entity.OntologyNode;
import com.swt.gap.model.entity.OntologyNodeProperty;
import com.swt.gap.model.entity.OntologyRelationshipProperty;
import com.swt.gap.model.vo.*;
import com.swt.gap.model.vo.graph.RelationshipBindVO;
import com.swt.gap.model.vo.ontology.OntologyNodeVO;
import com.swt.gap.service.CommonFileService;
import com.swt.gap.service.OntologyService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "本体，即图谱配置")
@RestController
@RequestMapping("/ontology")
@Slf4j
public class OntologyController {

    private final OntologyService ontologyService;
    private final CommonFileService commonFileService;

    public OntologyController(OntologyService ontologyService, CommonFileService commonFileService) {
        this.ontologyService = ontologyService;
        this.commonFileService = commonFileService;
    }

    @GetMapping("/{ontologyId}")
    @ApiOperation(value = "获取本体", notes = "获取本体")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = OntologyVO.class)})
    public ResponseEntity getOntology(@PathVariable Integer ontologyId) {
        return ResponseEntity.ok(ontologyService.getOntologyById(ontologyId));
    }


    @GetMapping("/node")
    @ApiOperation(value = "获取实体列表", notes = "获取实体列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = OntologyNodeVO.class)})
    public ResponseEntity listEntities() {
        return ResponseEntity.ok(ontologyService.listOntologyEntity());
    }

    @PostMapping("/node-icon")
    @ApiOperation(value = "上传icon", notes = "上传实体icon")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = CommonFileUploadVO.class, responseContainer = "List")})
    public ResponseEntity uploadEntityIcon(@RequestParam("files") MultipartFile[] files) {
        return ResponseEntity.ok(commonFileService.uploadFile(files, CommonConstant.ICON_PATH));
    }


    @PostMapping("/node")
    @ApiOperation(value = "新增节点类型", notes = "新增节点类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ontologyNodeVO", dataType = "OntologyNodeVO", paramType = "body", value = "实体类型信息"),

    })
    @ApiResponses({@ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity addOntologyEntity(@RequestBody OntologyNodeVO ontologyNodeVO) {
        //对实体类别名的校验
        String label = ontologyNodeVO.getLabels();
        if (StringUtils.isNotBlank(label)) {
            label = label.trim();
            if (label.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyNodeVO.setLabels(label);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("类型名称不能为空");
        }
        //判断重名
        Boolean isRepeat = ontologyService.judgeLabel(ontologyNodeVO.getType(), label, null);
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("类型已存在");
        }
        //判断属性是否重复
        List<OntologyNodeProperty> ontologyNodePropertyList = ontologyNodeVO.getOntologyNodePropertyList();
        List<String> keyList = ontologyNodePropertyList.stream().map(OntologyNodeProperty::getPropertyKey).collect(Collectors.toList());
        HashSet<String> hashSet = new HashSet<>(keyList);
        if (hashSet.size() != ontologyNodePropertyList.size()) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性名称重复");
        }
        ontologyService.addOntologyEntityAndProperty(ontologyNodeVO);
        return ResponseEntity.status(HttpStatus.CREATED).body(ontologyNodeVO);
    }

    @GetMapping("/node-label")
    @ApiOperation(value = "判断实体类型名称是否重名", notes = "判断实体类型名称是否重名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "label", dataType = "String", paramType = "query", value = "新增实体类型名称"),
            @ApiImplicitParam(name = "type", dataType = "int", paramType = "query", value = "1普通实体 2事件实体 3文档实体")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity judgeEntityLabel(@RequestParam String label, @RequestParam Integer type){
        if (StringUtils.isNotBlank(label)) {
            label = label.trim();
            if (label.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("类型名称不能为空");
        }
        //判断重名
        Boolean isRepeat = ontologyService.judgeLabel(type, label, null);
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("类型已存在");
        }
        return ResponseEntity.ok("可用");
    }


    @GetMapping("/node/type")
    @ApiOperation(value = "获取节点类型列表", notes = "获取节点类型列表")
    @ApiImplicitParam(name = "type", dataType = "int", paramType = "query", value = "1实体 2事件 3文档")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = NodeListVO.class)})
    public ResponseEntity listOntologyEntities(@RequestParam Integer type) {
        return ResponseEntity.ok(ontologyService.getOntologyEntityList(type));
    }



    @PutMapping("/node-label-icon/{nodeId}")
    @ApiOperation(value = "编辑名称或icon", notes = "编辑名称或icon")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nodeId", dataType = "int", paramType = "path", value = "实体类型Id"),
            @ApiImplicitParam(name = "content", dataType = "String", paramType = "query", value = "实体类型名称或icon"),
            @ApiImplicitParam(name = "iconId", dataType = "int", paramType = "query", value = "更改图标时传图标id", required = false),
            @ApiImplicitParam(name = "updateType", dataType = "int", paramType = "query", value = "编辑内容 0：实体类型名称 1：实体类型icon")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "修改成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity updateEntity(@PathVariable Integer nodeId, @RequestParam String content,
                                       @RequestParam Integer iconId, @RequestParam Integer updateType) {
        if (updateType.equals(0)) {
            if (StringUtils.isNotBlank(content)) {
                content = content.trim();
                if (content.length() > 10) {
                    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
                }
            } else {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("类型名称不能为空");
            }
        }
        ontologyService.updateEntity(nodeId, content, iconId, updateType);
        return ResponseEntity.ok("编辑成功");
    }


    @DeleteMapping("/node/{nodeId}")
    @ApiOperation(value = "删除实体类型", notes = "删除实体类型")
    @ApiImplicitParam(name = "nodeId", dataType = "int",paramType = "path", value = "实体类型Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    public ResponseEntity deleteEntity(@PathVariable Integer nodeId){
        return ResponseEntity.ok(ontologyService.deleteEntity(nodeId));
    }


    @GetMapping("/node/{nodeId}")
    @ApiOperation(value = "获取实体类型详情", notes = "获取实体类型详情")
    @ApiImplicitParam(name = "nodeId", dataType = "int",paramType = "path", value = "实体类型Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = OntologyNodeVO.class)})
    public ResponseEntity getOntologyEntityVO(@PathVariable Integer nodeId){
        return ResponseEntity.ok(ontologyService.getOntologyEntityVO(nodeId));
    }


    @PostMapping("/node/property")
    @ApiOperation(value = "实体类型属性添加或编辑", notes = "实体类型属性添加或编辑")
    @ApiImplicitParam(name = "ontologyNodeProperty", dataType = "OntologyNodeProperty", paramType = "body", value = "实体类型属性信息")
    @ApiResponses({@ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求"),
            @ApiResponse(code = 200, message = "编辑成功")
    })
    public ResponseEntity addOrUpdateEntityProperty(@RequestBody OntologyNodeProperty ontologyNodeProperty) {
        //对属性名的校验
        String propertyKey = ontologyNodeProperty.getPropertyKey();
        Integer propertyId = ontologyNodeProperty.getPropertyId();
        if (StringUtils.isNotBlank(propertyKey)) {
            propertyKey = propertyKey.trim();
            if (propertyKey.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyNodeProperty.setPropertyKey(propertyKey);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("属性名称不为空");
        }
        Boolean isRepeat = ontologyService.judgePropertyKey(ontologyNodeProperty.getNodeId(), ontologyNodeProperty.getPropertyKey(), propertyId);
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性已存在");
        }
        if (propertyId == null || propertyId < 1) {
            //添加属性
            ontologyService.addEntityProperty(ontologyNodeProperty);
            return ResponseEntity.status(HttpStatus.CREATED).body(ontologyNodeProperty);
        } else {
            ontologyService.updateEntityProperty(ontologyNodeProperty);
            return ResponseEntity.ok(ontologyNodeProperty);
        }
    }


    @DeleteMapping("/node/property/{propertyId}")
    @ApiOperation(value = "删除实体类型属性", notes = "删除实体类型属性")
    @ApiImplicitParam(name = "propertyId", dataType = "int",paramType = "path", value = "属性Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    public ResponseEntity deleteEntityProperty(@PathVariable Integer propertyId){
        return ResponseEntity.ok(ontologyService.deleteEntityProperty(propertyId));
    }

    @GetMapping("/node/labels")
    @ApiOperation(value = "获取所有二级实体类型名称", notes = "获取所有二级实体类型名称")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = OntologyNode.class)})
    public ResponseEntity listSecondEntities() {
        return ResponseEntity.ok(ontologyService.listSecondEntities());
    }


    @PostMapping("/relationship")
    @ApiOperation(value = "新增边类型", notes = "新增边类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ontologyRelationshipVO", dataType = "OntologyRelationshipVO", paramType = "body", value = "边类型信息"),

    })
    @ApiResponses({@ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity addOntologyRelationship(@RequestBody OntologyRelationshipVO ontologyRelationshipVO) {
        //对边类型名的校验
        Integer relationshipId = ontologyRelationshipVO.getRelationshipId();
        String type = ontologyRelationshipVO.getType();
        if (StringUtils.isNotBlank(type)) {
            type = type.trim();
            if (type.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyRelationshipVO.setType(type);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("类型名称不能为空");
        }
        if (ontologyRelationshipVO.getStartNodeId() == null || ontologyRelationshipVO.getStartNodeId() < 1) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("开始节点不能为空");
        }
        if (ontologyRelationshipVO.getEndNodeId() == null || ontologyRelationshipVO.getEndNodeId() < 1) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("结束节点不能为空");
        }
        //判断边重名
        Boolean isRepeat = ontologyService.judgeRelationship(ontologyRelationshipVO);
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("类型已存在");
        }
        //判断属性是否重复
        List<OntologyRelationshipProperty> relationshipPropertyList = ontologyRelationshipVO.getOntologyRelationshipPropertyList();
        List<String> keyList = relationshipPropertyList.stream().map(OntologyRelationshipProperty::getPropertyKey).collect(Collectors.toList());
        HashSet<String> hashSet = new HashSet<>(keyList);
        if (hashSet.size() != relationshipPropertyList.size()) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性名称重复");
        }
        //新增
        ontologyService.addRelationship(ontologyRelationshipVO);
        return ResponseEntity.status(HttpStatus.CREATED).body(ontologyRelationshipVO);
    }


    @GetMapping("/relationship-one/{relationshipId}")
    @ApiOperation(value = "获取边类型", notes = "获取边类型")
    @ApiImplicitParams ({
            @ApiImplicitParam(name = "relationshipId", dataType = "int",paramType = "path", value = "边Id"),
            @ApiImplicitParam(name = "currentId", dataType = "int",paramType = "query", value = "当前节点Id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = RelationshipVO.class)})
    public ResponseEntity getRelationship(@PathVariable Integer relationshipId, @RequestParam Integer currentId){
        return ResponseEntity.ok(ontologyService.getRelationship(relationshipId, currentId));
    }


    @PutMapping("/relationship/{relationshipId}")
    @ApiOperation(value = "编辑边类型", notes = "编辑边类型")
    @ApiImplicitParams ({
            @ApiImplicitParam(name = "relationshipId", dataType = "int",paramType = "path", value = "边类型Id"),
            @ApiImplicitParam(name = "ontologyRelationshipVO", dataType = "OntologyRelationshipVO",paramType = "body", value = "边类型信息")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok"),
                   @ApiResponse(code = 409, message = "已重名"),
                   @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity updateRelationship(@RequestBody OntologyRelationshipVO ontologyRelationshipVO, @PathVariable Integer relationshipId){
        ontologyRelationshipVO.setRelationshipId(relationshipId);
        //对边名的校验
        String type = ontologyRelationshipVO.getType();
        if(StringUtils.isNotBlank(type)){
            type = type.trim();
            if(type.length() > 10){
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过20");
            }
            ontologyRelationshipVO.setType(type);
        }else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称不能为空");
        }
        if (ontologyRelationshipVO.getStartNodeId() == null || ontologyRelationshipVO.getStartNodeId() < 1) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("开始节点不能为空");
        }
        if (ontologyRelationshipVO.getEndNodeId() == null || ontologyRelationshipVO.getEndNodeId() < 1) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("结束节点不能为空");
        }
        //判断边重名
        Boolean isRepeat = ontologyService.judgeRelationship(ontologyRelationshipVO);
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("类型已存在");
        }
        //判断属性是否重复
        List<OntologyRelationshipProperty> relationshipPropertyList = ontologyRelationshipVO.getOntologyRelationshipPropertyList();
        List<String> keyList = relationshipPropertyList.stream().map(OntologyRelationshipProperty::getPropertyKey).collect(Collectors.toList());
        HashSet<String> hashSet = new HashSet<>(keyList);
        if (hashSet.size() != relationshipPropertyList.size()) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性名称重复");
        }
        ontologyService.updateRelationship(ontologyRelationshipVO);
        return ResponseEntity.ok(ontologyRelationshipVO);
    }



    @DeleteMapping("/relationship/{relationshipId}")
    @ApiOperation(value = "删除边的类型", notes = "删除边的类型")
    @ApiImplicitParam(name = "relationshipId", dataType = "int",paramType = "path", value = "边类型Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    public ResponseEntity deleteRelationship(@PathVariable Integer relationshipId){
        return ResponseEntity.ok(ontologyService.deleteRelationship(relationshipId));
    }


    @GetMapping("/relationship/{nodeId}")
    @ApiOperation(value = "获取边的绑定", notes = "获取边的绑定")
    @ApiImplicitParam(name = "nodeId", dataType = "int",paramType = "path", value = "当前实体类型Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = RelationshipBindVO.class)})
    public ResponseEntity getEntityRelationshipVO(@PathVariable Integer nodeId){
        return ResponseEntity.ok(ontologyService.getEntityRelationshipVOs(nodeId));
    }


    @GetMapping("/relationship-node")
    @ApiOperation(value = "获取选中节点的边信息", notes = "获取选中节点的边信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentId", dataType = "int",paramType = "query", value = "当前节点Id"),
            @ApiImplicitParam(name = "selectId", dataType = "int",paramType = "query", value = "选中关联节点Id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = NodeRelationshipVO.class)})
    public ResponseEntity selectEntityRelationshipVO(@RequestParam Integer currentId, @RequestParam Integer selectId){
        return ResponseEntity.ok(ontologyService.selectEntityRelationshipVOs(currentId, selectId));
    }


    @GetMapping("/relationship-edge/{relationshipId}")
    @ApiOperation(value = "获取选中边的边信息", notes = "获取选中边的边信息")
    @ApiImplicitParam(name = "relationshipId", dataType = "int",paramType = "path", value = "边类型Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = NodeRelationshipVO.class)})
    public ResponseEntity selectEntityRelationshipById(@PathVariable Integer relationshipId){
        return ResponseEntity.ok(ontologyService.selectEntityRelationshipById(relationshipId));
    }


    /*@DeleteMapping("/relationship/property/{propertyId}")
    @ApiOperation(value = "删除边类型属性", notes = "删除边类型属性")
    @ApiImplicitParam(name = "propertyId", dataType = "int",paramType = "path", value = "属性Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    public ResponseEntity deleteRelationshipProperty(@PathVariable Integer propertyId){
        return ResponseEntity.ok(ontologyService.deleteRelationshipProperty(propertyId));
    }*/


    /*@PostMapping("/relationship/property")
    @ApiOperation(value = "边属性添加", notes = "边属性添加")
    @ApiImplicitParam(name = "ontologyRelationshipProperty", dataType = "OntologyRelationshipProperty", paramType = "body", value = "边类型属性信息")
    @ApiResponses({@ApiResponse(code = 201, message = "添加成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")
    })
    public ResponseEntity addRelationshipProperty(@RequestBody OntologyRelationshipProperty ontologyRelationshipProperty) {
        //对属性名的校验
        String propertyKey = ontologyRelationshipProperty.getPropertyKey();
        if (StringUtils.isNotBlank(propertyKey)) {
            propertyKey = propertyKey.trim();
            if (propertyKey.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyRelationshipProperty.setPropertyKey(propertyKey);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("属性名称不为空");
        }
        Boolean isRepeat = ontologyService.judgeRelationshipKey(null, propertyKey, ontologyRelationshipProperty.getRelationshipId());
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性已存在");
        }
        return ResponseEntity.status(HttpStatus.CREATED).body(ontologyService.addRelationshipProperty(ontologyRelationshipProperty));
    }*/


    /*@PutMapping("/relationship/property")
    @ApiOperation(value = "边属性编辑", notes = "边属性编辑")
    @ApiImplicitParam(name = "ontologyRelationshipProperty", dataType = "OntologyRelationshipProperty", paramType = "body", value = "边类型属性信息")
    @ApiResponses({@ApiResponse(code = 200, message = "编辑成功"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")
    })
    public ResponseEntity updateRelationshipProperty(@RequestBody OntologyRelationshipProperty ontologyRelationshipProperty) {
        //对属性名的校验
        String propertyKey = ontologyRelationshipProperty.getPropertyKey();
        if (StringUtils.isNotBlank(propertyKey)) {
            propertyKey = propertyKey.trim();
            if (propertyKey.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyRelationshipProperty.setPropertyKey(propertyKey);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("属性名称不为空");
        }
        Boolean isRepeat = ontologyService.judgeRelationshipKey(ontologyRelationshipProperty.getPropertyId(), propertyKey, ontologyRelationshipProperty.getRelationshipId());
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("属性已存在");
        }
        return ResponseEntity.ok(ontologyService.updateRelationshipProperty(ontologyRelationshipProperty));
    }*/

    /*@GetMapping("/entity/count-property-key")
    @ApiOperation(value = "根据label获取可统计的属性key", notes = "根据label获取可统计的属性key")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labels", dataType = "array",paramType = "query", value = "节点labels 数组")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = CountPropertyKeyVO.class, responseContainer = "List")})
    public ResponseEntity<List<CountPropertyKeyVO>> listCountPropertyKeyByLabels(@RequestParam String[] labels){
        return ResponseEntity.ok(ontologyService.listCountPropertyKeyByLabels(labels));
    }*/

    @GetMapping("/relationship-property")
    @ApiOperation(value = "根据labels获取关系以及属性", notes = "根据labels获取关系以及属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startLabels", dataType = "String",paramType = "query", value = "文档节点的labels"),
            @ApiImplicitParam(name = "endLabels", dataType = "String",paramType = "query", value = "对方节点的labels")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = RelationshipAndPropertyVO.class, responseContainer = "List")
    })
    public ResponseEntity<List<RelationshipAndPropertyVO>> getEntityRelationshipVO(@RequestParam String startLabels, @RequestParam String endLabels){
        return ResponseEntity.ok(ontologyService.listRelationshipByLabels(startLabels, endLabels));
    }


    @GetMapping("/relationship/property")
    @ApiOperation(value = "判断边属性名称是否重名", notes = "判断边属性名称是否重名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ontologyRelationshipProperty", dataType = "OntologyRelationshipProperty", paramType = "body", value = "新增或修改的属性")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok"),
            @ApiResponse(code = 409, message = "已重名"),
            @ApiResponse(code = 400, message = "非法请求")})
    public ResponseEntity judgeRelationshipProperty(@RequestBody OntologyRelationshipProperty ontologyRelationshipProperty){
        String propertyKey = ontologyRelationshipProperty.getPropertyKey();
        if (StringUtils.isNotBlank(propertyKey)) {
            propertyKey = propertyKey.trim();
            if (propertyKey.length() > 10) {
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("名称长度不能超过10");
            }
            ontologyRelationshipProperty.setPropertyKey(propertyKey);
        } else {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("类型名称不能为空");
        }
        //判断重名
        Boolean isRepeat = ontologyService.judgeRelationshipKey(ontologyRelationshipProperty.getPropertyId(), propertyKey, ontologyRelationshipProperty.getRelationshipId());
        if (isRepeat) {
            return ResponseEntity.status(HttpStatus.CONFLICT).body("类型已存在");
        }
        return ResponseEntity.ok("可用");
    }

}
